<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: WillPaginate::ViewHelpers</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">WillPaginate::ViewHelpers</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/plugins/will_paginate/lib/will_paginate/view_helpers_rb.html">
                vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <h1>Will Paginate view helpers</h1>
<p>
The main view helper, <a href="ViewHelpers.html#M000013">will_paginate</a>,
renders pagination links for the given collection. The helper itself is
lightweight and serves only as a wrapper around <a
href="LinkRenderer.html">LinkRenderer</a> instantiation; the renderer then
does all the hard work of generating the HTML.
</p>
<h2>Global options for helpers</h2>
<p>
Options for pagination helpers are optional and get their default values
from the <tt>WillPaginate::ViewHelpers.pagination_options</tt> hash. You
can write to this hash to override default options on the global level:
</p>
<pre>
  WillPaginate::ViewHelpers.pagination_options[:previous_label] = 'Previous page'
</pre>
<p>
By putting this into &quot;config/initializers/will_paginate.rb&quot; (or
simply environment.rb in older versions of Rails) you can easily translate
link texts to previous and next pages, as well as override some other
defaults to your liking.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000015">page_entries_info</a>&nbsp;&nbsp;
      <a href="#M000014">paginated_section</a>&nbsp;&nbsp;
      <a href="#M000013">will_paginate</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000015" class="method-detail">
        <a name="M000015"></a>

        <div class="method-heading">
          <a href="#M000015" class="method-signature">
          <span class="method-name">page_entries_info</span><span class="method-args">(collection, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Renders a helpful message with numbers of displayed vs. total entries. You
can use this as a blueprint for your own, similar helpers.
</p>
<pre>
  &lt;%= page_entries_info @posts %&gt;
  #-&gt; Displaying posts 6 - 10 of 26 in total
</pre>
<p>
By default, the message will use the humanized class name of objects in
collection: for instance, &quot;project types&quot; for ProjectType models.
Override this with the <tt>:entry_name</tt> parameter:
</p>
<pre>
  &lt;%= page_entries_info @posts, :entry_name =&gt; 'item' %&gt;
  #-&gt; Displaying items 6 - 10 of 26 in total
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000015-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb, line 167</span>
167:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">page_entries_info</span>(<span class="ruby-identifier">collection</span>, <span class="ruby-identifier">options</span> = {})
168:       <span class="ruby-identifier">entry_name</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:entry_name</span>] <span class="ruby-operator">||</span>
169:         (<span class="ruby-identifier">collection</span>.<span class="ruby-identifier">empty?</span><span class="ruby-value">? </span><span class="ruby-value str">'entry'</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">underscore</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-value str">'_'</span>, <span class="ruby-value str">' '</span>))
170:       
171:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">total_pages</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">2</span>
172:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">size</span>
173:         <span class="ruby-keyword kw">when</span> <span class="ruby-value">0</span>; <span class="ruby-node">&quot;No #{entry_name.pluralize} found&quot;</span>
174:         <span class="ruby-keyword kw">when</span> <span class="ruby-value">1</span>; <span class="ruby-node">&quot;Displaying &lt;b&gt;1&lt;/b&gt; #{entry_name}&quot;</span>
175:         <span class="ruby-keyword kw">else</span>;   <span class="ruby-node">&quot;Displaying &lt;b&gt;all #{collection.size}&lt;/b&gt; #{entry_name.pluralize}&quot;</span>
176:         <span class="ruby-keyword kw">end</span>
177:       <span class="ruby-keyword kw">else</span>
178:         <span class="ruby-node">%{Displaying #{entry_name.pluralize} &lt;b&gt;%d&amp;nbsp;-&amp;nbsp;%d&lt;/b&gt; of &lt;b&gt;%d&lt;/b&gt; in total}</span> <span class="ruby-operator">%</span> [
179:           <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">offset</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>,
180:           <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">offset</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">length</span>,
181:           <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">total_entries</span>
182:         ]
183:       <span class="ruby-keyword kw">end</span>
184:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000014" class="method-detail">
        <a name="M000014"></a>

        <div class="method-heading">
          <a href="#M000014" class="method-signature">
          <span class="method-name">paginated_section</span><span class="method-args">(*args) {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Wrapper for rendering pagination links at both top and bottom of a block of
content.
</p>
<pre>
  &lt;% paginated_section @posts do %&gt;
    &lt;ol id=&quot;posts&quot;&gt;
      &lt;% for post in @posts %&gt;
        &lt;li&gt; ... &lt;/li&gt;
      &lt;% end %&gt;
    &lt;/ol&gt;
  &lt;% end %&gt;
</pre>
<p>
will result in:
</p>
<pre>
  &lt;div class=&quot;pagination&quot;&gt; ... &lt;/div&gt;
  &lt;ol id=&quot;posts&quot;&gt;
    ...
  &lt;/ol&gt;
  &lt;div class=&quot;pagination&quot;&gt; ... &lt;/div&gt;
</pre>
<p>
Arguments are passed to a <tt><a
href="ViewHelpers.html#M000013">will_paginate</a></tt> call, so the same
options apply. Don&#8216;t use the <tt>:id</tt> option; otherwise
you&#8216;ll finish with two blocks of pagination links sharing the same ID
(which is invalid HTML).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000014-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb, line 142</span>
142:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">paginated_section</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
143:       <span class="ruby-identifier">pagination</span> = <span class="ruby-identifier">will_paginate</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>).<span class="ruby-identifier">to_s</span>
144:       
145:       <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">ActionView</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:erb_variable</span>
146:         <span class="ruby-identifier">concat</span> <span class="ruby-identifier">pagination</span>
147:         <span class="ruby-keyword kw">yield</span>
148:         <span class="ruby-identifier">concat</span> <span class="ruby-identifier">pagination</span>
149:       <span class="ruby-keyword kw">else</span>
150:         <span class="ruby-identifier">content</span> = <span class="ruby-identifier">pagination</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">capture</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">pagination</span>
151:         <span class="ruby-identifier">concat</span>(<span class="ruby-identifier">content</span>, <span class="ruby-identifier">block</span>.<span class="ruby-identifier">binding</span>)
152:       <span class="ruby-keyword kw">end</span>
153:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000013" class="method-detail">
        <a name="M000013"></a>

        <div class="method-heading">
          <a href="#M000013" class="method-signature">
          <span class="method-name">will_paginate</span><span class="method-args">(collection = nil, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Renders Digg/Flickr-style pagination for a <a
href="Collection.html">WillPaginate::Collection</a> object. Nil is returned
if there is only one page in total; no point in rendering the pagination in
that case&#8230;
</p>
<h4>Options</h4>
<p>
Display options:
</p>
<ul>
<li><tt>:previous_label</tt> &#8212; default: &quot;« Previous&quot; (this
parameter is called <tt>:prev_label</tt> in versions <b>2.3.2</b> and
older!)

</li>
<li><tt>:next_label</tt> &#8212; default: &quot;Next »&quot;

</li>
<li><tt>:page_links</tt> &#8212; when false, only previous/next links are
rendered (default: true)

</li>
<li><tt>:inner_window</tt> &#8212; how many links are shown around the current
page (default: 4)

</li>
<li><tt>:outer_window</tt> &#8212; how many links are around the first and the
last page (default: 1)

</li>
<li><tt>:separator</tt> &#8212; string separator for page HTML elements
(default: single space)

</li>
</ul>
<p>
HTML options:
</p>
<ul>
<li><tt>:class</tt> &#8212; CSS class name for the generated DIV (default:
&quot;pagination&quot;)

</li>
<li><tt>:container</tt> &#8212; toggles rendering of the DIV container for
pagination links, set to false only when you are rendering your own
pagination markup (default: true)

</li>
<li><tt>:id</tt> &#8212; HTML ID for the container (default: nil). Pass
<tt>true</tt> to have the ID automatically generated from the class name of
objects in collection: for example, paginating ArticleComment models would
yield an ID of &quot;article_comments_pagination&quot;.

</li>
</ul>
<p>
Advanced options:
</p>
<ul>
<li><tt>:param_name</tt> &#8212; parameter name for page number in URLs
(default: <tt>:page</tt>)

</li>
<li><tt>:params</tt> &#8212; additional parameters when generating pagination
links (eg. <tt>:controller =&gt; &quot;foo&quot;, :action =&gt; nil</tt>)

</li>
<li><tt>:renderer</tt> &#8212; class name, class or instance of a link renderer
(default: <tt><a
href="LinkRenderer.html">WillPaginate::LinkRenderer</a></tt>)

</li>
</ul>
<p>
All options not recognized by <a
href="ViewHelpers.html#M000013">will_paginate</a> will become HTML
attributes on the container element for pagination links (the DIV). For
example:
</p>
<pre>
  &lt;%= will_paginate @posts, :style =&gt; 'font-size: small' %&gt;
</pre>
<p>
&#8230; will result in:
</p>
<pre>
  &lt;div class=&quot;pagination&quot; style=&quot;font-size: small&quot;&gt; ... &lt;/div&gt;
</pre>
<h4>Using the helper without arguments</h4>
<p>
If the helper is called without passing in the collection object, it will
try to read from the instance variable inferred by the controller name. For
example, calling <tt><a
href="ViewHelpers.html#M000013">will_paginate</a></tt> while the current
controller is PostsController will result in trying to read from the
<tt>@posts</tt> variable. Example:
</p>
<pre>
  &lt;%= will_paginate :id =&gt; true %&gt;
</pre>
<p>
&#8230; will result in <tt>@post</tt> collection getting paginated:
</p>
<pre>
  &lt;div class=&quot;pagination&quot; id=&quot;posts_pagination&quot;&gt; ... &lt;/div&gt;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000013-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb, line 89</span>
 89:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">will_paginate</span>(<span class="ruby-identifier">collection</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">options</span> = {})
 90:       <span class="ruby-identifier">options</span>, <span class="ruby-identifier">collection</span> = <span class="ruby-identifier">collection</span>, <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Hash</span>
 91:       <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">collection</span> <span class="ruby-keyword kw">or</span> <span class="ruby-operator">!</span><span class="ruby-identifier">controller</span>
 92:         <span class="ruby-identifier">collection_name</span> = <span class="ruby-node">&quot;@#{controller.controller_name}&quot;</span>
 93:         <span class="ruby-identifier">collection</span> = <span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">collection_name</span>)
 94:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;The #{collection_name} variable appears to be empty. Did you &quot;</span> <span class="ruby-operator">+</span>
 95:           <span class="ruby-value str">&quot;forget to pass the collection object for will_paginate?&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">collection</span>
 96:       <span class="ruby-keyword kw">end</span>
 97:       <span class="ruby-comment cmt"># early exit if there is nothing to render</span>
 98:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">WillPaginate</span><span class="ruby-operator">::</span><span class="ruby-constant">ViewHelpers</span>.<span class="ruby-identifier">total_pages_for_collection</span>(<span class="ruby-identifier">collection</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
 99:       
100:       <span class="ruby-identifier">options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">symbolize_keys</span>.<span class="ruby-identifier">reverse_merge</span> <span class="ruby-constant">WillPaginate</span><span class="ruby-operator">::</span><span class="ruby-constant">ViewHelpers</span>.<span class="ruby-identifier">pagination_options</span>
101:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:prev_label</span>]
102:         <span class="ruby-constant">WillPaginate</span><span class="ruby-operator">::</span><span class="ruby-constant">Deprecation</span><span class="ruby-operator">::</span><span class="ruby-identifier">warn</span>(<span class="ruby-value str">&quot;:prev_label view parameter is now :previous_label; the old name has been deprecated.&quot;</span>)
103:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:previous_label</span>] = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:prev_label</span>)
104:       <span class="ruby-keyword kw">end</span>
105:       
106:       <span class="ruby-comment cmt"># get the renderer instance</span>
107:       <span class="ruby-identifier">renderer</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:renderer</span>]
108:       <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>
109:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:renderer</span>].<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">constantize</span>.<span class="ruby-identifier">new</span>
110:       <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Class</span>
111:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:renderer</span>].<span class="ruby-identifier">new</span>
112:       <span class="ruby-keyword kw">else</span>
113:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:renderer</span>]
114:       <span class="ruby-keyword kw">end</span>
115:       <span class="ruby-comment cmt"># render HTML for pagination</span>
116:       <span class="ruby-identifier">renderer</span>.<span class="ruby-identifier">prepare</span> <span class="ruby-identifier">collection</span>, <span class="ruby-identifier">options</span>, <span class="ruby-keyword kw">self</span>
117:       <span class="ruby-identifier">renderer</span>.<span class="ruby-identifier">to_html</span>
118:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>